<%--
  Created by IntelliJ IDEA.
  User: Yancyxiaoone
  Date: 2022/11/13
  Time: 14:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <style>
        table {
            position: relative;
        }

        td {
            white-space: nowrap;
        }

        #span {
            position: absolute;
        }
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>注册</title>
    <script src="js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            //用户名文本框绑定失去焦点事件
            $("#username").blur(function () {
                if ($("#username").val() != "") {
                    $.ajax({
                        url: "userCheckAjax",//设置服务器地址
                        type: "post",//提交方式
                        data: {username: $(this).val()},//提交到服务器的数据，多个值以逗号分割
                        success: function (data) { //回调函数，data是返回的数据
                            // alert("data: " + data);
                            $("#span").html(data);
                        }
                    });
                } else {
                    $("#span").html("");
                }
            });
        });
    </script>
    <script>
        function fun() {
            window.location.href = 'login.jsp';
        }
    </script>
<body>
<jsp:include page="/head.jsp"/>
<form action="register" method="post" style="text-align: center">
    <h1>用户注册</h1>
    <table style="margin: auto">
        <tr>
            <td>姓名</td>
            <td><input type="text" name="username" id="username"/></td>
            <td rowspan="2"><span id="span"></span></td>
        </tr>
        <tr>
            <td>密码</td>
            <td><input type="password" name="password"/></td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="登录" onclick="fun()"/>
                <input type="submit" value="注册"/>
            </td>
        </tr>
    </table>
</form>

</body>
</html>